import MySQL


def save():
    MySQL.save('tpch_query', {
        'query_type': 'accurate',
        'related_tables': 'lineitem',
        'group': 1,
        'base_sql': """SELECT l_returnflag, l_linestatus, sum(l_quantity) AS sum_qty, sum(l_extendedprice) AS sum_base_price, sum(l_extendedprice * (1 - l_discount)) AS sum_disc_price, sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) AS sum_charge, avg(l_quantity) AS avg_qty, avg(l_extendedprice) AS avg_price, avg(l_discount) AS avg_disc, count(*) AS count_order FROM lineitem_data_200w WHERE l_shipdate <= DATE ''1998-12-01''- INTERVAL ''108'' DAY GROUP BY l_returnflag, l_linestatus ORDER BY l_returnflag, l_linestatus""".replace(
            '\n', '')
    })


def query():
    return MySQL.query('select * from tpch_query')


if __name__ == '__main__':
    print(query())
